using System;
using System.Data;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Threading;
using System.Globalization;
using System.Text;
using System.IO;
using Smarty;
using Data;
using SubSonic;
using System.Web;
using System.Xml;

public class articleMasterList
{
    public static string CreateMasterTableInfo(string detailtable, string[] keys, System.Web.UI.Page page)
    {
        string strTableName = "article";
        string oldTableName = strTableName;
        string keyField = string.Empty;
        string output = string.Empty;
        Dictionary<string, object> smarty = new Dictionary<string, object>();
        Builder builder = Factory.CreateBuilder();

        smarty.Add("__table", strTableName);
            string sCulture = ConfigurationManager.AppSettings["LCID"];
            if (!String.IsNullOrEmpty(sCulture)) 
            {
                int nCulture = int.Parse(sCulture);
                smarty.Add("LCID", nCulture);
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(nCulture, false);
            } 
                if(System.Web.HttpContext.Current.Session["locale_xml"] != null)
        {
            smarty.Add("Captions", AspNetRunnerPage.GetTableCaptions((XmlNode)System.Web.HttpContext.Current.Session["locale_xml"], 
                (string)System.Web.HttpContext.Current.Session["language"]));
            if(!string.IsNullOrEmpty(strTableName))
            {
                smarty.Add("Labels", AspNetRunnerPage.GetFieldCaptions((XmlNode)System.Web.HttpContext.Current.Session["locale_xml"], 
                    (string)System.Web.HttpContext.Current.Session["language"], "article"));
            }
        }
        IDictionary<string, object> par = new Dictionary<string, object>();
	        keyField = "ArtCateID";
        par[keyField] = keys[1 - 1];

        articleController controller = new articleController();
        article item = controller.FetchByManyID(par);

	    string keylink = string.Empty;
        if(item != null)
        {
	    keylink += "&key1=" + Control.HTMLEncodeSpecialChars(HttpUtility.UrlEncode(item.ArtID.ToString()));
        }
        	
        string value="";

        Control control_ArtID = new Control("ArtID", item.ArtID, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	ArtID - 
	                            value = control_ArtID.GetData();
			        value = control_ArtID.ProcessLargeText(value,"field=ArtID" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("ArtID_mastervalue",value);

        Control control_ArtCateID = new Control("ArtCateID", item.ArtCateID, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	ArtCateID - 
	                            control_ArtCateID.Value = func.GetLookupValue(control_ArtCateID.FieldInfo);
                    value=control_ArtCateID.DisplayLookupWizard();
			        smarty.Add("ArtCateID_mastervalue",value);

        Control control_Title = new Control("Title", item.Title, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	Title - 
	                            value = control_Title.GetData();
			        value = control_Title.ProcessLargeText(value,"field=Title" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("Title_mastervalue",value);

        Control control_ShortDescript = new Control("ShortDescript", item.ShortDescript, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	ShortDescript - 
	                            value = control_ShortDescript.GetData();
			        value = control_ShortDescript.ProcessLargeText(value,"field=ShortDescript" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("ShortDescript_mastervalue",value);

        Control control_Content = new Control("Content", item.Content, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	Content - 
	                            value = control_Content.GetData();
			        value = control_Content.ProcessLargeText(value,"field=Content" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("Content_mastervalue",value);

        Control control_Active = new Control("Active", item.Active, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	Active - Checkbox
	        			        value = control_Active.GetData();
			        smarty.Add("Active_mastervalue",value);

        Control control_Status = new Control("Status", item.Status, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	Status - 
	                            value = control_Status.GetData();
			        value = control_Status.ProcessLargeText(value,"field=Status" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("Status_mastervalue",value);

        Control control_VipLevel = new Control("VipLevel", item.VipLevel, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	VipLevel - 
	                            value = control_VipLevel.GetData();
			        value = control_VipLevel.ProcessLargeText(value,"field=VipLevel" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("VipLevel_mastervalue",value);

        Control control_Viewed = new Control("Viewed", item.Viewed, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	Viewed - Number
	                            value = control_Viewed.GetData();
			        value = control_Viewed.ProcessLargeText(value,"field=Viewed" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("Viewed_mastervalue",value);

        Control control_Image = new Control("Image", item.Image, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	Image - 
	                            value = control_Image.GetData();
			        value = control_Image.ProcessLargeText(value,"field=Image" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("Image_mastervalue",value);

        Control control_Author = new Control("Author", item.Author, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	Author - 
	                            value = control_Author.GetData();
			        value = control_Author.ProcessLargeText(value,"field=Author" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("Author_mastervalue",value);

        Control control_Hot = new Control("Hot", item.Hot, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	Hot - Checkbox
	        			        value = control_Hot.GetData();
			        smarty.Add("Hot_mastervalue",value);

        Control control_CreatedDate = new Control("CreatedDate", item.CreatedDate, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	CreatedDate - Short Date
	                            value = control_CreatedDate.GetData();
			        value = control_CreatedDate.ProcessLargeText(value,"field=CreatedDate" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("CreatedDate_mastervalue",value);

        Control control_UpdatedDate = new Control("UpdatedDate", item.UpdatedDate, false, smarty, page.Request, builder, MODE.MODE_LIST);
        //	UpdatedDate - Short Date
	                            value = control_UpdatedDate.GetData();
			        value = control_UpdatedDate.ProcessLargeText(value,"field=UpdatedDate" + keylink,"",MODE.MODE_LIST);
			        smarty.Add("UpdatedDate_mastervalue",value);
            return func.BuildOutput(page, @"~\admin\article_masterlist.aspx", smarty);
    }
}
